package homework12月9号补交.homework2.d9;

import java.lang.reflect.Constructor;
import java.util.ArrayList;

public class test {
    public static void main(String[] args) throws Exception {
        Object o = newInstance("czxy.homework2.d9.DemoClass", new Object[]{"1"});
        System.out.println(o);
    }
    public static Object newInstance (String className, Object[] args) throws Exception{
        Class<?> aClass = Class.forName(className);
        ArrayList<Class> arr = new ArrayList<>();
        for (Object arg : args) {
            System.out.println(arg.getClass().toString());
            arr.add(arg.getClass().toString().getClass());
            Class<? extends String> aClass1 = arg.getClass().toString().getClass();
        }
        //将集合 数据 转移到数组
        Class[] classes = arr.toArray(new Class[0]);
        Constructor<?> constructor = aClass.getConstructor(classes);
        Object o = constructor.newInstance(args);
        return o;
    }
}
